package com.sqbr.video.common.interceptor;

import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    @Autowired
    private CustomInterceptor customInterceptor;
    // 注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new SaInterceptor(handler -> {
                    // 获取所有的URL并进行检查
                    SaRouter.notMatch
                            ("/doc.html",
                            "/swagger-resources/**",
                            "/webjars/**",
                            "/swagger-ui.html/**",
                            "/swagger-ui/**",
                            "/v2/**",
                            "/user/test",
                            "/user/register",
                            "/user/pwdLogin"
                            )
                            .match("/**").check(() -> {

                        // 检查是否登录
                        StpUtil.checkLogin();
                    });
                }));
    }


}
